/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kasus.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.*;
import kasus.model.Kelengkapan;
import kasus.model.Mahasiswa;
import kasus.model.*;

/**
 *
 * @author mei
 */
public class PanelDaftarYudisium extends JPanel {

    private JLabel judul;
    private JLabel labelNim, labelNama, labelProdi, labelNoHp, labelPeriodeYudisium, labelKelengkapan;
    private JComboBox ComboPeriodeYudisium;
    private JTextField textNim, textNama, textProdi, textNoHp, textPeriodeYudisium, textUpload;
    private JButton tombolSimpan, tombolUpload;
    private JCheckBox cek1, cek2, cek3, cek4, cek5, cek6, cek7;
    private JLabel label1, label2, label3, label4, label5, label6, label7;
    private JTable tabel;
    private BufferedImage image;
    private File file;
    Object[][] mData;

    public PanelDaftarYudisium() {
        setLayout(null);

        judul = new JLabel("FORM DAFTAR YUDISIUM");
        judul.setBounds(220, 0, 200, 50);
        judul.setVisible(true);
        this.add(judul);

        labelNim = new JLabel("Nim");
        labelNim.setBounds(50, 50, 200, 50);
        labelNim.setVisible(true);
        this.add(labelNim);

        textNim = new javax.swing.JFormattedTextField();
        textNim.setPreferredSize(new java.awt.Dimension(60, 20));
        textNim.setBounds(170, 60, 280, 30);
        textNim.setVisible(true);
        this.add(textNim);

        labelNama = new JLabel("Nama");
        labelNama.setBounds(50, 90, 200, 50);
        labelNama.setVisible(true);
        this.add(labelNama);

        textNama = new javax.swing.JFormattedTextField();
        textNama.setPreferredSize(new java.awt.Dimension(60, 20));
        textNama.setBounds(170, 100, 280, 30);
        textNama.setVisible(true);
        this.add(textNama);

        labelProdi = new JLabel("Prodi");
        labelProdi.setBounds(50, 130, 200, 50);
        labelProdi.setVisible(true);
        this.add(labelProdi);

        textProdi = new javax.swing.JFormattedTextField();
        textProdi.setPreferredSize(new java.awt.Dimension(60, 20));
        textProdi.setBounds(170, 140, 280, 30);
        textProdi.setVisible(true);
        this.add(textProdi);

        labelNoHp = new JLabel("No HP");
        labelNoHp.setBounds(50, 170, 200, 50);
        labelNoHp.setVisible(true);
        this.add(labelNoHp);

        textNoHp = new javax.swing.JFormattedTextField();
        textNoHp.setPreferredSize(new java.awt.Dimension(60, 20));
        textNoHp.setBounds(170, 180, 280, 30);
        textNoHp.setVisible(true);
        this.add(textNoHp);

        labelPeriodeYudisium = new JLabel("Periode Yudisium");
        labelPeriodeYudisium.setBounds(50, 210, 200, 50);
        labelPeriodeYudisium.setVisible(true);
        this.add(labelPeriodeYudisium);

        String course[] = {" ", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"};

        ComboPeriodeYudisium = new JComboBox(course);
        ComboPeriodeYudisium.setBounds(170, 220, 280, 30);
        ComboPeriodeYudisium.setVisible(true);
        this.add(ComboPeriodeYudisium);

        textPeriodeYudisium = new javax.swing.JFormattedTextField();
        textPeriodeYudisium.setPreferredSize(new java.awt.Dimension(60, 20));
        textPeriodeYudisium.setBounds(170, 220, 280, 30);
        textPeriodeYudisium.setVisible(true);
        this.add(textPeriodeYudisium);

        labelKelengkapan = new JLabel("Kelengkapan");
        labelKelengkapan.setBounds(50, 250, 200, 50);
        labelKelengkapan.setVisible(true);
        this.add(labelKelengkapan);

        cek1 = new JCheckBox();
        cek1.setBounds(170, 265, 20, 20);
        cek1.setVisible(true);
        this.add(cek1);

        label1 = new JLabel("Daftar Nilai");
        label1.setBounds(210, 250, 200, 50);
        label1.setVisible(true);
        this.add(label1);

        cek2 = new JCheckBox();
        cek2.setBounds(170, 305, 20, 20);
        cek2.setVisible(true);
        this.add(cek2);

        label2 = new JLabel("Naskah TA");
        label2.setBounds(210, 290, 200, 50);
        label2.setVisible(true);
        this.add(label2);

        cek3 = new JCheckBox();
        cek3.setBounds(170, 345, 20, 20);
        cek3.setVisible(true);
        this.add(cek3);

        label3 = new JLabel("bebas pinjam(lab)");
        label3.setBounds(210, 330, 200, 50);
        label3.setVisible(true);
        this.add(label3);

        cek4 = new JCheckBox();
        cek4.setBounds(330, 265, 20, 20);
        cek4.setVisible(true);
        this.add(cek4);

        label4 = new JLabel("bebas pinjam dari dosen");
        label4.setBounds(370, 250, 200, 50);
        label4.setVisible(true);
        this.add(label4);

        cek5 = new JCheckBox();
        cek5.setBounds(330, 305, 20, 20);
        cek5.setVisible(true);
        this.add(cek5);

        label5 = new JLabel("penyerahan laporan KP");
        label5.setBounds(370, 290, 200, 50);
        label5.setVisible(true);
        this.add(label5);

        cek6 = new JCheckBox();
        cek6.setBounds(330, 345, 20, 20);
        cek6.setVisible(true);
        this.add(cek6);

        label6 = new JLabel("surat keterangan KKL/KI");
        label6.setBounds(370, 330, 200, 50);
        label6.setVisible(true);
        this.add(label6);

        cek7 = new JCheckBox();
        cek7.setBounds(170, 385, 20, 20);
        cek7.setVisible(true);
        this.add(cek7);

        label7 = new JLabel("surat keterangan bebas pinjam : ");
        label7.setBounds(210, 370, 200, 50);
        label7.setVisible(true);
        this.add(label7);

        tombolUpload = new javax.swing.JButton("upload");
        tombolUpload.setPreferredSize(new java.awt.Dimension(120, 60));
        this.add(tombolUpload);
        tombolUpload.setBounds(380, 420, 100, 30);

        tombolUpload.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                tombolCariGambarAction();
            }
        });

        textUpload = new javax.swing.JFormattedTextField();
        textUpload.setPreferredSize(new java.awt.Dimension(60, 20));
        textUpload.setBounds(210, 420, 160, 30);
        textUpload.setVisible(true);
        this.add(textUpload);

        tombolSimpan = new javax.swing.JButton("simpan");
        tombolSimpan.setPreferredSize(new java.awt.Dimension(120, 60));
        this.add(tombolSimpan);
        tombolSimpan.setBounds(235, 400, 150, 50);
        tombolSimpan.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                tombolSimpanAction();
            }
        });
    }

    public void tombolCariGambarAction() {
        try {
            JFileChooser chooser = new JFileChooser();
            int status = chooser.showOpenDialog(this);
            int APPROVE_ACTION = 0;
            if (status == APPROVE_ACTION) {
                setFile(chooser.getSelectedFile());
                textUpload.setText(chooser.getSelectedFile().getPath());
                repaint();
            }
            setImage(ImageIO.read(getFile()));
            getImage().getGraphics();
        } catch (IOException ex) {
            Logger.getLogger(PanelDaftarYudisium.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void tombolSimpanAction() {
        Mahasiswa agg = new Mahasiswa();
        Kelengkapan kl = new Kelengkapan();
        try {

            agg.setNim(Integer.parseInt(textNim.getText()));
            agg.setNama(textNama.getText());
            agg.setNomor_hp(textNoHp.getText());
            agg.setProdi(textProdi.getText());
            agg.setPeriode_yudisium(Integer.parseInt(textPeriodeYudisium.getText()));

            if (cek1.isSelected() == true) {
                cek1.setText("Ada");
                kl.setDaftar_nilai(cek1.getText());

            } else {
                cek1.setText("Tidak Ada");
                kl.setDaftar_nilai(cek1.getText());

            }

            if (cek2.isSelected() == true) {

                cek2.setText("Ada");
                kl.setNaskah_TA(cek2.getText());
            } else {
                cek2.setText("Tidak Ada");

                kl.setNaskah_TA(cek2.getText());

            }
            if (cek3.isSelected() == true) {

                cek3.setText("Ada");
                kl.setBebas_pinjam_dari_laboratorium(cek3.getText());
            } else {
                cek3.setText("Tidak Ada");
                kl.setBebas_pinjam_dari_laboratorium(cek3.getText());

            }
            if (cek4.isSelected() == true) {
                cek4.setText("Ada");
                kl.setBebas_pinjam_dari_dosen(cek4.getText());

            } else {
                cek4.setText("Tidak Ada");
                kl.setBebas_pinjam_dari_dosen(cek4.getText());

            }
            if (cek5.isSelected() == true) {
                cek5.setText("Ada");
                kl.setBukti_penyerahan_laporan_KP(cek5.getText());

            } else {
                cek5.setText("Tidak Ada");
                kl.setBukti_penyerahan_laporan_KP(cek5.getText());

            }
            if (cek6.isSelected() == true) {
                cek6.setText("Ada");
                kl.setSurat_keterangan_KKL_KI(cek6.getText());

            } else {
                cek6.setText("Tidak Ada");
                kl.setSurat_keterangan_KKL_KI(cek6.getText());

            }

            if (cek1.isSelected() == true && cek2.isSelected() == true && cek3.isSelected() == true && cek4.isSelected() == true && cek5.isSelected() == true && cek6.isSelected() == true) {

                JOptionPane.showMessageDialog(null, "Semua Data Sudah Dilengkapi");
            } else {
                JOptionPane.showMessageDialog(null, "Ada Data Yang Belum Dilengkapi");
            }


            TestConnectionOracle t = new TestConnectionOracle();
            java.sql.Statement statement = t.logon().createStatement();
            String sql = "INSERT INTO MAHASISWA(NIM,NAMA,PRODI,NOHP,PERIODEYUDISIUM,DAFTARNILAI,NASKAHTA,BEBASPINJAMLAB,BEBASPINJAMDARIDOSEN,BUKTILAPDARIKP,SURATKKNKI)" + "VALUES('" + agg.getNim() + "','" + agg.getNama() + "','" + agg.getProdi() + "','" + agg.getNomor_hp() + "','" + agg.getPeriode_yudisium() + "','" + kl.getDaftar_nilai() + "','" + kl.getNaskah_TA() + "','" + kl.getBebas_pinjam_dari_laboratorium() + "','" + kl.getBebas_pinjam_dari_dosen() + "','" + kl.getBukti_penyerahan_laporan_KP() + "','" + kl.getSurat_keterangan_KKL_KI() + "')";
            statement.executeUpdate(sql);
            statement.close();
            JOptionPane.showMessageDialog(null, "Data Berhasil Diinputkan ke Database");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Data Tidak Berhasil Diinputkan ke Database" + ex);
        }
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public BufferedImage getImage() {
        return image;
    }

    public void setImage(BufferedImage image) {
        this.image = image;
    }
}
